"""Property matching schemas for AI-enhanced property recommendation."""

from __future__ import annotations

from datetime import datetime

from pydantic import BaseModel, Field

from ..schemas.property import PropertyOut


class MatchScoreBreakdown(BaseModel):
    """匹配分数明细（完全可解释）."""

    budget_score: float = Field(..., ge=0, le=100, description="预算匹配分(0-100)")
    layout_score: float = Field(..., ge=0, le=100, description="户型匹配分(0-100)")
    area_score: float = Field(..., ge=0, le=100, description="区域匹配分(0-100)")
    tag_score: float = Field(..., ge=0, le=100, description="标签匹配分(0-100)")
    commute_score: float = Field(0, ge=0, le=100, description="通勤匹配分数(如果有通勤需求)")
    semantic_bonus: float = Field(0, ge=0, le=10, description="语义匹配加分(0-10)")
    total_score: float = Field(..., ge=0, le=100, description="综合得分(0-100)")


class PropertyMatchResult(BaseModel):
    """单个房源匹配结果."""

    property_id: int = Field(..., description="房源ID")
    property: PropertyOut = Field(..., description="完整房源信息")
    match_score: float = Field(..., ge=0, le=100, description="匹配度(0-100分)")
    score_breakdown: MatchScoreBreakdown = Field(..., description="分数明细")
    match_reasons: list[str] = Field(default_factory=list, description="匹配理由(前3条)")
    mismatch_reasons: list[str] = Field(default_factory=list, description="不匹配理由")
    ai_insights: list[str] = Field(
        default_factory=list, description="AI额外洞察(如: '通勤时间仅15分钟')"
    )


class PropertyMatchListResponse(BaseModel):
    """匹配房源列表响应."""

    lead_id: int = Field(..., description="客户ID")
    total_matched: int = Field(..., description="匹配房源总数")
    matches: list[PropertyMatchResult] = Field(..., description="匹配结果列表(按分数降序)")
    computed_at: datetime = Field(default_factory=datetime.utcnow, description="计算时间戳")
